//Saturday, October 31 2009
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <math.h>
#include <sstream>
#include <algorithm>

using namespace std;

int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

class FindingSquareInTable
{
	public:
		int row;
		int col;
		int findMaximalSquare(vector <string> table)
		{
			int ret = -1;
			row = table.size();
			col = table[0].size();

			for(int i=0; i<row; i++)
				for(int j=0; j<col; j++)
					for(int m=-row; m<=row; m++)
						for(int n=-col; n<=col; n++)
			{
				if(m==0 && n==0) continue;
				int value = 0;
				int x = i;
				int y = j;
				while( inbound(x, y) )
				{
					value = value * 10 + (table[x][y]-'0');
					if(issquare(value))
						ret = max(ret, value);
					x += m;
					y += n;
				}
			}
			return ret;
		}
		bool issquare(int n)
		{
			int m = (int)sqrt(n);
			if(m*m == n) return true;
			return false;
		}
		bool inbound(int x, int y)
		{
			return (x>=0 && x<row && y>=0 && y<col);
		}
};
